package com.taobao.client.pages;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.taobao.client.RPC;
import com.taobao.client.buyer.custom.CustomButton;
import com.taobao.client.obj.TopRefund;
import com.taobao.client.util.PopBox;

public class AddTradeMemo {

	static final Button closeButton = new Button("关闭");
	static DialogBox dialogBox;
	
	CustomButton customerButton;
	public AddTradeMemo(final CustomButton customerButton) {
		this.customerButton = customerButton;
	}
	
	public void show(){
		dialogBox = new DialogBox();
		dialogBox.setText("备注");
		dialogBox.setAnimationEnabled(true);

		// We can set the id of a widget by accessing its Element
		closeButton.getElement().setId("closeButton");

		VerticalPanel dialogVPanel = new VerticalPanel();
		dialogVPanel.addStyleName("dialogVPanel");
		dialogVPanel.add(new HTML("<b>输入订单备注</b>"));
		
		final TextArea input = new TextArea();
		
		input.setSize("500px", "200px");
		
		
		dialogVPanel.add(input);
		
		Button addButton = new Button("添加订单备注");
		dialogVPanel.add(addButton);
		
		addButton.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent arg0) {
				customerButton.setTradeMemo(input.getText());
				
				RPC.getService().addTradeMemo(input.getText(), customerButton.getTradeId(),new AsyncCallback<TopRefund>() {
					@Override
					public void onSuccess(TopRefund arg0) {
						PopBox.ok("添加成功", "添加成功");
					}
					
					@Override
					public void onFailure(Throwable arg0) {
						PopBox.ok("添加失败", "添加失败"+arg0.getMessage());
					}
				});
				dialogBox.hide();
			}
		});

		dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
		dialogVPanel.add(closeButton);
		dialogBox.setWidget(dialogVPanel);

		// Add a handler to close the DialogBox
		closeButton.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				dialogBox.hide();
			}
		});
		dialogBox.show();
		dialogBox.center();
	}
}
